#!/usr/bin/python2.4
#
# Copyright 2010 Google Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import unittest

import twoarchive
import base
from solution import Solution


class TestGopt(unittest.TestCase):
	def setUp(self):
		self.problem = base.Problem(2, 10, 10)
		self.algorithm = twoarchive.TwoArchive(self.problem, 10, 10)

	def test_Solution(self):
		self.s1 = Solution(self.problem)
		self.assertEqual(self.problem.numberOfTests, len(self.s1.gene))

	def test_Crossover(self):
		print "crossover test\n"
		self.s1 = Solution(self.problem)
		self.s2 = Solution(self.problem)

		print "parents"
		print self.s1.gene
		print self.s2.gene

		before = self.s1.gene.__or__(self.s2.gene)

		offsprings = self.algorithm.crossover([self.s1, self.s2])

		print
		print "offspring"
		print offsprings[0].gene
		print offsprings[1].gene

		after = offsprings[0].gene.__or__(offsprings[1].gene)
		self.assertEqual(before, after)

	def test_Mutation(self):
		print "mutation test\n"
		self.s1 = Solution(self.problem)
		print self.s1.gene
		self.algorithm.mutate(self.s1)
		print self.s1.gene

if __name__ == '__main__':
	unittest.main()
